#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int fa[550];
struct node
{
	int x;
	int y;
	int d;
}p[20000000];
bool cmp(node a,node b)
{
	return a.d<b.d;
}
int find(int x)
{
	if(fa[x]==x) return x;
	else return find(fa[x]);
}
int judge(int x, int y)
{
	x = find(x);
	y = find(y);
	if(x==y) return 0;
	else
	{
		fa[y] = x;
		return 1 ;
	}
}
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int t = 0;
		for(int i = 1;i<=n;i++) fa[i] = i;
		for(int i = 1;i<=n;i++)
		{
			for(int j = 1;j<=n;j++)
			{
				int m;
				scanf("%d",&m);
				if(j>i) 
				{
					t++;
					p[t].x = i;
					p[t].y = j;
					p[t].d = m; 
				}
			}
		}
		sort(p+1,p+1+t,cmp);
		int ans = 0;
		for(int i = 1;i<=t;i++)
		{	
			//printf("%d %d\n",p[i])
			if(judge(p[i].x,p[i].y))
			{
				ans += p[i].d;
			
			}
		}
		printf("%d\n",ans);
	}
}
